FROM alpine:3.19

ENV PHPIZE_DEPS="autoconf dpkg-dev dpkg file tar zip g++ gcc libc-dev make pkgconf re2c pcre-dev pcre2-dev zlib-dev libtool automake"

RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories

COPY ./run.sh /run.sh

RUN apk update \
	&& apk add  php81 php81-pear php81-dev openssl curl bash ca-certificates libaio-dev openssl-dev curl-dev \
                php81-mysqli php81-pdo_mysql php81-mbstring php81-json php81-zlib php81-gd php81-intl php81-session php81-fpm \
                php81-curl php81-posix php81-fileinfo php81-simplexml php81-opcache php81-sodium \
                php81-tokenizer php81-ctype php81-bcmath php81-openssl php81-dom \ 
                php81-iconv php81-sockets php81-zip php81-pcntl php81-xmlwriter php81-xmlreader php81-redis php81-xml php81-phar \
                php81-pecl-event \
    && apk add --no-cache --virtual .build-deps $PHPIZE_DEPS \
	&& apk --no-cache add tzdata \
    && cp "/usr/share/zoneinfo/Asia/Shanghai" /etc/localtime \
    && echo "Asia/Shanghai" > /etc/timezone \
    && update-ca-certificates \
    && mkdir /www \
    && sed 's/user = nobody/user = root/g' /etc/php81/php-fpm.d/www.conf | sed 's/group = nobody/group = root/g'| sed 's/127.0.0.1/0.0.0.0/g' | sed 's/pm.max_children = 5/pm.max_children = 30/g' | sed 's/pm = dynamic/pm = static/g' > /tmp/www.conf \
    && mv /tmp/www.conf /etc/php81/php-fpm.d/www.conf \
    && apk add gnu-libiconv libstdc++ --no-cache --repository http://mirrors.aliyun.com/alpine/edge/community/ --allow-untrusted \
    && sed 's/;opcache.enable=1/opcache.enable=1/g' /etc/php81/php.ini | sed 's/;opcache.validate_timestamps=1/opcache.validate_timestamps=0/g' | sed 's/;opcache.memory_consumption=128/opcache.memory_consumption=128/g' | sed 's/;opcache.interned_strings_buffer=8/opcache.interned_strings_buffer=8/g' | sed 's/;opcache.max_accelerated_files=10000/opcache.max_accelerated_files=10000/g' > /tmp/php.ini \
    && mv /tmp/php.ini /etc/php81/php.ini \
    && ln -s /usr/sbin/php-fpm81 /usr/sbin/php-fpm \
    #&& ln -s /usr/bin/php81 /usr/bin/php \
    #&& ln -s /usr/bin/phar81 /usr/bin/phar \
    #&& ln -s /usr/bin/php-config81 /usr/bin/php-config \
    #&& ln -s /usr/bin/phpize81 /usr/bin/phpize \
    && chmod +x /run.sh \
    && wget https://mirrors.tencent.com/composer/composer.phar \
    && mv composer.phar  /usr/local/bin/composer \
    && chmod 755 /usr/local/bin/composer 
     # ---------- clear works ----------
    #&& apk del .build-deps \
    #&& rm -rf /var/cache/apk/* /tmp/* /usr/share/man /usr/local/bin/php* \
    #&& composer config -g repos.packagist composer https://mirrors.tencent.com/composer/

#RUN apk add --no-cache nginx \
#	&& touch /run/nginx/nginx.pid \
#	&& sed 's/user nginx;/user root;/g' /etc/nginx/nginx.conf | sed 's/#gzip on;/gzip on;/g' > /tmp/nginx.conf \
#	&& mv /tmp/nginx.conf /etc/nginx/nginx.conf 

#COPY ./nginx.conf /etc/nginx/http.d/default.conf

WORKDIR /www

EXPOSE 8787 9000

CMD ["/run.sh"]